package edu.xidian.bdilab.jrbigdata.service.enterprise.login.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.xidian.bdilab.jrbigdata.controller.enterprise.EnterpriseCode;
import edu.xidian.bdilab.jrbigdata.controller.response.ResponseResult;
import edu.xidian.bdilab.jrbigdata.domain.EnterpriseUser;
import edu.xidian.bdilab.jrbigdata.mapper.EnterpriseUserMapper;

import edu.xidian.bdilab.jrbigdata.service.enterprise.login.EnterpriseLoginService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EnterpriseLoginServiceImpl implements EnterpriseLoginService {
    @Autowired
    EnterpriseUserMapper enterpriseuserMapper;

    @Override
   public ResponseResult responsResult(String name, String password)
   {
       QueryWrapper<EnterpriseUser> userWrapper = new QueryWrapper<>();
       //UpdateWrapper<Enterpriseuser>updateWrapper=new UpdateWrapper<>();

       userWrapper.eq("user_name",name);

       EnterpriseUser person= enterpriseuserMapper.selectOne(userWrapper);
       if(person==null)
       {
           ResponseResult responseResult = new ResponseResult();
           responseResult.setCode(EnterpriseCode.USERNAME_NULL.getCode());
           responseResult.setMessage(EnterpriseCode.USERNAME_NULL.getMessage());
           responseResult.setSuccess(false);
           return responseResult;
       }



      else{
          if(person.getPassword().equals(password))
          {
              ResponseResult responseResult = new ResponseResult();
              responseResult.setCode(EnterpriseCode.LOGINSUCCESS.getCode());
              responseResult.setMessage(EnterpriseCode.LOGINSUCCESS.getMessage());
              responseResult.setSuccess(true);
              return responseResult;
          }
          else
          {
              ResponseResult responseResult = new ResponseResult();
              responseResult.setCode(EnterpriseCode.PASSWORD_WRONG.getCode());
              responseResult.setMessage(EnterpriseCode.PASSWORD_WRONG.getMessage());
              responseResult.setSuccess(false);
              return responseResult;
          }
      }

   }

}
